package geom;


public class AxisAngle {
	private float a;
	private Vector v;
	
	public AxisAngle(){
		v = new Vector();
		reset();
	}
	
	public AxisAngle(float x, float y, float z, float a){
		v = new Vector();
		set(x, y, z, a);
	}
	
	public AxisAngle(Vector v, float a){
		this.v = v;
		this.a = a;
	}
	
	public void reset(){
		setX(0);
		setY(0);
		setZ(1);
		setA(0);
	}
	
	public void set(AxisAngle aa){
		set(aa.v, aa.a);
	}
	
	public void set(Vector v, float a){
		this.v.set(v);
	}
	
	public void set(float x, float y, float z, float a){
		setX(x);
		setY(y);
		setZ(z);
		setA(a);
	}

	public float getA() {
		return a;
	}

	public float getX() {
		return v.x;
	}

	public float getY() {
		return v.y;
	}

	public float getZ() {
		return v.z;
	}
	
	public Vector getVector(){
		return v;
	}

	public void setA(float a) {
		this.a = a;
	}

	public void setX(float x) {
		v.x = x;
	}

	public void setY(float y) {
		v.y = y;
	}

	public void setZ(float z) {
		v.z = z;
	}
	
	public void set(float az, float el, float ro){
		set(Geom.eulerToAxisAngle(az, el, ro));
	}
	
	public String toString(){
		StringBuffer sb = new StringBuffer();
		sb.append("Axis:");
		sb.append(v.toString());
		sb.append(" Angle: ");
		sb.append(a);
		return sb.toString();
	}
	
	public AxisAngle subtract(AxisAngle aa){
		Vector x = v.xProdut(aa.v);
		Vector axis = v.mult(a).sub(aa.v.mult(aa.a)).add(x).normalize();
		float o = (float)Math.asin(x.absLength());
		float w = a - aa.a; 
		float angle = (float)Math.sqrt(o*o + w*w);
		return new AxisAngle(axis, angle);
	}
	
	public AxisAngle getCopy(){
		return new AxisAngle(v.x, v.y, v.z, a);
	}
	
	public boolean equalTo(AxisAngle aa){
		if(a != aa.getA()) return false;
		if(!v.equalTo(aa.getVector())) return false;
		return true;
	}
}
